package com.cskaoyan.controller.mall;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.PageDataVo;
import com.cskaoyan.bean.mall.issue.Issue;
import com.cskaoyan.service.mall.IssueService;
import com.cskaoyan.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @description: 商场管理模块——通用问题
 * @author: enhui
 **/
@RestController
@RequestMapping("admin/issue")
public class IssueController {
    @Autowired
    IssueService issueService;

    @RequestMapping("list")
    public BaseRespVo issueList(String question, BaseParam param) {
        PageDataVo basePageData = issueService.issueList(question, param);
        if (basePageData == null) {
            return BaseRespVo.error();
        }
        return BaseRespVo.ok(basePageData);
    }

    @RequestMapping("create")
    public BaseRespVo createIssue(@RequestBody Issue issue) {
        Issue issueCreate = issueService.createIssue(issue);
        if (issueCreate == null) {
            return BaseRespVo.error("新建问题失败");
        }
        return BaseRespVo.ok(issueCreate);
    }

    @RequestMapping("update")
    public BaseRespVo updateIssue(@RequestBody Issue issue) {
        Issue issueUpdate = issueService.updateIssue(issue);
        if (issueUpdate == null) {
            return BaseRespVo.error("更新问题失败");
        }
        return BaseRespVo.ok(issueUpdate);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteIssue(@RequestBody Issue issue) {
        int code = issueService.deleteIssue(issue);
        if (code == Constant.SUCCESS) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error("删除问题失败");
    }
}
